/*******************************************************************************
 * Copyright (c) 2008, 2009 Fabio Mauro - Alberto Terraneo.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 1.2
 * or any later version published by the Free Software Foundation.
 *     
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Free Documentation License for more details.
 *     
 * You should have received a copy of the GNU Free Documentation 
 * License along with this distribution; if not, send a email to authors:
 * aterraneo <at> users.sourceforge.net
 * bigmoby09 <at> users.sourceforge.net
 *******************************************************************************/
package it.blueocean.acanto.web.platform.components.tabs.tabpanel;

import it.blueocean.acanto.model.MenuItem;
import it.blueocean.acanto.web.platform.components.tabs.tabpanel.components.DynamicButtons;
import it.blueocean.acanto.web.platform.components.tabs.tabpanel.container.CustomSecureButtonPanel;

import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;

import org.apache.log4j.Logger;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

public class ButtonPanelContainer extends Panel
{
	private static final long serialVersionUID = -803972511389878990L;

	private static final Logger logger = Logger.getLogger(ButtonPanelContainer.class);

	public ButtonPanelContainer(String id, SortedSet<MenuItem> children)
	{
		super(id, new Model<Integer>(new Integer(-1)));

		if(children == null || children.size() == 0)
		{
			logger.error("argument [children] cannot be null or empty for tabId [" + id + "]");
			throw new IllegalArgumentException("argument [children] cannot be null or empty for tabId [" + id + "]");
		}

		List<DynamicButtons> buttonList = new ArrayList<DynamicButtons>();

		for (MenuItem menuItem : children)
		{
			DynamicButtons button = new DynamicButtons(menuItem);
			buttonList.add(button);
		}
		
		Panel buttonBar = getButtonBar("buttons", buttonList);
		
		add(buttonBar);
	}
	
	private Panel getButtonBar(String id, List<DynamicButtons> buttonList)
	{
		CustomSecureButtonPanel secureTabbedPanel = new CustomSecureButtonPanel(id, buttonList);

		return secureTabbedPanel;
	}
}
